import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;
    private static final int DEFAULT = 10;

    public MyStack(){
        elem = new int[DEFAULT];
    }

    public void push(int val){//模拟入栈操作
        if(isFull()){//如果满了就扩容
            grow();
        }
        elem[usedSize] = val;
        usedSize++;
    }

    private void grow(){
        elem = Arrays.copyOf(elem,elem.length);
    }

    public boolean isFull(){//判断数组是否满了
        return usedSize == elem.length;
    }

    public int pop() {
        if(isEmpty()){
            throw new StackIsEmpty("栈为空");
        }
        usedSize--;//相当于把数据置为null
        return elem[usedSize-1];
    }

    public boolean isEmpty(){
        return usedSize == 0;
    }

    public int peek() {
        if(isEmpty()){
            throw new StackIsEmpty("栈为空");
        }
        return elem[usedSize--];
    }

    public int size(){
        return usedSize;
    }
}
